package com.tchhy.provider.repository

import com.tchhy.provider.api.ProfitApi
import com.tchhy.provider.data.common.BaseResp
import com.tchhy.provider.data.common.EmptyResp
import com.tchhy.provider.data.common.SmsVO
import com.tchhy.provider.data.partner.response.DataListRes
import com.tchhy.provider.data.profit.response.IncomeBreakdownRes
import com.tchhy.provider.data.profit.response.IncomeRes
import com.tchhy.provider.data.profit.response.SettlementIncomeRes
import com.tchhy.provider.net.RetrofitFactory
import com.tchyy.provider.data.BindBankInfo
import com.tchyy.provider.data.CashInfo
import com.tchyy.provider.data.CashRecord
import io.reactivex.Observable

/**
 * @author: admin
 * @date: 2019/8/20
 * @des:
 *
 **/
class ProfitRepository : BaseRepository() {
    fun sendCaptcha(smsVO: SmsVO): Observable<EmptyResp>{
        return  RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .sendCaptcha(getRequestJsonBody(smsVO))
    }
    /**
     * 绑定的银行卡列表
     */
    fun bankCardList(): Observable<BaseResp<List<BindBankInfo>>> {
        return  RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .bankCardList()
    }

    /**
     * 绑定银行卡
     */
    fun bindBankCard(bindBankInfo: BindBankInfo): Observable<EmptyResp> {
        return  RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .bindBankCard(getRequestJsonBody(bindBankInfo))
    }


    /**
     * 解绑定银行卡
     */
    fun unbindBankCard(bankCardId:Long): Observable<EmptyResp> {
        return  RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .unbindBankCard(bankCardId)
    }


    /**
     * 申请提现
     */
    fun cashApply(cashInfo: CashInfo): Observable<BaseResp<Boolean>> {
        return  RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .cashApply(getRequestJsonBody(cashInfo))
    }


    /**
     * 提现记录
     */
    fun cashRecordList(pageNum: Int, pageSize: Int): Observable<BaseResp<DataListRes<CashRecord>>> {
        return  RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .cashRecordList(pageNum, pageSize)
    }


    /**
     * 我的收益
     */
    fun myIncome(): Observable<BaseResp<IncomeRes>> {
        return RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .myIncome()
    }

    /**
     * 结算单列表
     */
    fun billList(pageNum: Int, pageSize: Int): Observable<BaseResp<DataListRes<IncomeBreakdownRes>>> {
        return RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .billList(pageNum, pageSize)
    }

    /**
     * 结算详情
     */
    fun settlementDetailsById(settlementId: Long): Observable<BaseResp<IncomeBreakdownRes>> {
        return RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .settlementDetailsById(settlementId)
    }

    /**
     * 收益结算明细列表
     */
    fun detailedListOfBenefits(
        pageNum: Int,
        pageSize: Int,
        startTime: String,
        endTime: String,
        serviceType: Int,
        serviceId: Long
    ): Observable<BaseResp<DataListRes<SettlementIncomeRes>>> {
        return RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .detailedListOfBenefits(pageNum, pageSize, startTime, endTime, serviceType, serviceId)
    }

    /**
     * 收益列表
     */
    fun incomeBreakdownList(
        pageNum: Int,
        pageSize: Int,
        date: String?,
        type: Int?
    ): Observable<BaseResp<DataListRes<SettlementIncomeRes>>> {
        return RetrofitFactory.instance
            .createApiService(ProfitApi::class.java)
            .incomeBreakdownList(pageNum, pageSize, date, type)
    }
}